package com.east.config.shiro;

import java.io.UnsupportedEncodingException;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.web.bind.annotation.ModelAttribute;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.east.bean.User;


public class BaseController {
	protected User stu;
	
	@ModelAttribute
	public void UserId() {
		Subject subject = SecurityUtils.getSubject();
		System.out.println(JSON.toJSON(subject.getPrincipal()));
		 String user=(String)subject.getPrincipal();
	        byte[] decodeBase64 = Base64.decodeBase64(user);
	        String string=null;
			try {
				string = new String(decodeBase64,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 stu = JSON.parseObject(string,new TypeReference<User>() {});
	}
}	
